<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传测试</title>
    <script src="http://47.106.66.89:8080/js/axios.min.js"></script>
</head>
<body>
    <form action="uploads/upload/img/" method="post" enctype="multipart/form-data">
        上传文件1：<input type="file" name="file"><br>
        上传文件2：<input type="file" name="file"><br>
        上传文件3：<input type="file" name="file"><br>
        上传文件4：<input type="file" name="file" multiple><br>
        <button>上传</button>
        <button type="button" onclick="upload()">ajax文件上传</button>
    </form>
<script>
    function upload(){
        let fd = new FormData();
        let inputs = document.getElementsByTagName("input");
        for (let i = 0; i < inputs.length; i++) {
            let input = inputs[i];
            if (input.files && input.files.length){
                for (let j = 0; j < input.files.length; j++){
                    let file = input.files[j]
                    console.log(file)
                    fd.append("file",file);
                }
            }
        }

        if(fd.getAll("file").length == 0){
            alert("请选择上传的文件");
            return;
        }
        axios.post("uploads/upload/img/",fd).then(resp=>{
            console.log(resp);
            alert(resp.data.msg);
        });
    }
</script>
</body>
</html>